package com.ruoyi.web.controller.project;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.OrderInfo;
import com.ruoyi.system.domain.vo.OrderInfoVO;
import com.ruoyi.system.domain.vo.OrderShiftCostRequest;
import com.ruoyi.system.service.IOrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/project/order")
public class OrderInfoController {
    @Autowired
    private IOrderInfoService orderInfoService;

    @GetMapping("/{orderId}")
    public AjaxResult getOrder(@PathVariable int orderId) {
        OrderInfo order = orderInfoService.selectOrderById(orderId);
        return AjaxResult.success(order);
    }

    @GetMapping("/list")
    public AjaxResult listOrders(OrderInfo orderInfo) {
        List<OrderInfo> list = orderInfoService.selectOrderList(orderInfo);
        return AjaxResult.success(list);
    }

    @PostMapping("/shiftCostCal")
    public AjaxResult shiftCostCal(OrderShiftCostRequest request) {
        return AjaxResult.success(orderInfoService.shiftCostCal(request));
    }
    @PostMapping("/add")
    public AjaxResult addOrder(@RequestBody OrderInfoVO orderInfo) {
        int result = orderInfoService.insertOrder(orderInfo);
        return result > 0 ? AjaxResult.success() : AjaxResult.error();
    }

    @PostMapping("/update")
    public AjaxResult updateOrder(@RequestBody OrderInfo orderInfo) {
        int result = orderInfoService.updateOrder(orderInfo);
        return result > 0 ? AjaxResult.success() : AjaxResult.error();
    }
} 